package my.action.author;
import javax.servlet.http.*;

import my.controller.*;
import my.db.DAO.AuthenticationDAO;
import my.db.DAO.AuthorDAO;
import my.db.DTO.AuthenticationDTO;
import my.db.DTO.AuthorDTO;
public class AuthorDeleteAction implements  Action{
	 public ActionForward execute(HttpServletRequest request,HttpServletResponse response) throws Exception{
		
		 // Fields
		 	AuthorDAO autDAO=new AuthorDAO();// object AuthorDAO
			AuthorDTO dto=null; // object AuthorDTO
		   	ActionForward forward=new ActionForward(); // object forward
		   	String name[]=request.getParameterValues("check_id");// select value from checkbox return array value
			String select="";//store result
			boolean result=true;// return true or false
			
		//Checking condition single value or multiple value
		   	if(name !=null){// if value is exised
		   		// Single delete
				 if(name.length==1){  
					 select=name[0]; // return only one value
					}else{
						//Multiple delete 
						for( int i=0;i<name.length;i++){
							select+=name[i]; // return multiple value 
							if(i <name.length-1){
								select+=",";
							}
						}
					}
				//Checking condtion true or false 
				   	forward.setRedirect(true);
			   		try{   			
			   			result=autDAO.delete(select);// delete value
			   			if(result==true){   
			   				forward.setPath("./admin_load.jsp");// call action list_author
			   			}
			  		}catch(Exception ex){
			  			System.out.println(ex);
			   		}
			 }else{
				 forward.setPath("./admin_load.jsp");// call action list_author
			 }	 
	  		return forward;
		}  	
}